package com.sztx.pay.center.rpc.service;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.sztx.pay.center.common.annotation.SlaveQueryAnnotation;
import com.sztx.pay.center.common.util.Constance;
import com.sztx.pay.center.common.util.CurrencyUtil;
import com.sztx.pay.center.common.util.DateUtil;
import com.sztx.pay.center.common.yhbf.YHBFSensitiveEnc;
import com.sztx.pay.center.common.yhbf.YHBFUtil;
import com.sztx.pay.center.core.service.CallBackService;
import com.sztx.pay.center.core.service.RiskTradeTypeService;
import com.sztx.pay.center.core.service.SettleService;
import com.sztx.pay.center.core.service.TreadQueryService;
import com.sztx.pay.center.dataaccess.dao.hbase.DumpOrderHbaseDAO;
import com.sztx.pay.center.dataaccess.dao.mysql.OrderRefundMysqlDAO;
import com.sztx.pay.center.dataaccess.dao.mysql.PayFlowMysqlDAO;
import com.sztx.pay.center.dataaccess.dao.mysql.RiskTradeTypeMysqlDAO;
import com.sztx.pay.center.dataaccess.dao.mysql.UserActFlowMysqlDAO;
import com.sztx.pay.center.dataaccess.dao.mysql.UserAmountCollectMysqlDAO;
import com.sztx.pay.center.dataaccess.domain.CallbackNotifyDO;
import com.sztx.pay.center.dataaccess.domain.HbaseQueryDO;
import com.sztx.pay.center.dataaccess.domain.OrderB2cDO;
import com.sztx.pay.center.dataaccess.domain.OrderMappingDO;
import com.sztx.pay.center.dataaccess.domain.OrderRechargeDO;
import com.sztx.pay.center.dataaccess.domain.OrderRefundDO;
import com.sztx.pay.center.dataaccess.domain.OrderTransferDO;
import com.sztx.pay.center.dataaccess.domain.OrderWithdrawDO;
import com.sztx.pay.center.dataaccess.domain.PayFlowDO;
import com.sztx.pay.center.dataaccess.domain.RiskTradeTypeDO;
import com.sztx.pay.center.dataaccess.domain.SettleOrderDO;
import com.sztx.pay.center.dataaccess.domain.UserActFlowDO;
import com.sztx.pay.center.dataaccess.domain.UserAmountCollectDO;
import com.sztx.pay.center.dataaccess.entity.QueryCallback;
import com.sztx.pay.center.dataaccess.entity.QueryOrder;
import com.sztx.pay.center.dataaccess.entity.QuerySettle;
import com.sztx.pay.center.rpc.api.domain.PageModelResponse;
import com.sztx.pay.center.rpc.api.domain.QueryHbaseOrderResp;
import com.sztx.pay.center.rpc.api.domain.UserAmountCollectResponse;
import com.sztx.pay.center.rpc.api.domain.request.QueryHbaseOrderRequest;
import com.sztx.pay.center.rpc.api.domain.request.QueryOrderCallback;
import com.sztx.pay.center.rpc.api.domain.request.QueryOrderRequest;
import com.sztx.pay.center.rpc.api.domain.request.QueryOrderSettle;
import com.sztx.pay.center.rpc.api.domain.request.QueryUserAccountFlow;
import com.sztx.pay.center.rpc.api.domain.response.OrderB2C;
import com.sztx.pay.center.rpc.api.domain.response.OrderB2CList;
import com.sztx.pay.center.rpc.api.domain.response.OrderCallback;
import com.sztx.pay.center.rpc.api.domain.response.OrderCallbackList;
import com.sztx.pay.center.rpc.api.domain.response.OrderRecharge;
import com.sztx.pay.center.rpc.api.domain.response.OrderRechargeList;
import com.sztx.pay.center.rpc.api.domain.response.OrderRefund;
import com.sztx.pay.center.rpc.api.domain.response.OrderRefundList;
import com.sztx.pay.center.rpc.api.domain.response.OrderSettle;
import com.sztx.pay.center.rpc.api.domain.response.OrderSettleList;
import com.sztx.pay.center.rpc.api.domain.response.OrderTransfer;
import com.sztx.pay.center.rpc.api.domain.response.OrderTransferList;
import com.sztx.pay.center.rpc.api.domain.response.OrderWithdraw;
import com.sztx.pay.center.rpc.api.domain.response.OrderWithdrawList;
import com.sztx.pay.center.rpc.api.domain.response.PayFlow;
import com.sztx.pay.center.rpc.api.domain.response.PayFlowList;
import com.sztx.pay.center.rpc.api.domain.response.QueryOrderStateResponse;
import com.sztx.pay.center.rpc.api.domain.response.UserActFlow;
import com.sztx.pay.center.rpc.api.domain.response.UserActFlowList;
import com.sztx.pay.center.rpc.api.service.QueryService;
import com.sztx.se.common.exception.BusinessException;
import com.sztx.se.common.util.StringUtil;
import com.sztx.se.common.util.validate.ValidateUtil;
import com.sztx.se.core.service.impl.BaseServiceImpl;
import com.sztx.se.dataaccess.mysql.config.PageQuery;
import com.sztx.se.rpc.dubbo.client.DubboClientFactory;
import com.sztx.trade.payment.gateway.rpc.api.service.trade.ReqQryOrder;
import com.sztx.trade.payment.gateway.rpc.api.service.trade.RespQryOrder;
import com.sztx.trade.payment.gateway.rpc.api.service.trade.TradeRpcService;

@Service
public class QueryServiceImpl extends BaseServiceImpl implements QueryService {

	@Autowired
	private TreadQueryService treadQueryService;

	@Autowired
	private CallBackService callBackService;

	@Autowired
	private SettleService settleService;

	@Autowired
	private UserActFlowMysqlDAO userActFlowMysqlDAO;
	
	@Autowired
	private OrderRefundMysqlDAO orderRefundMysqlDAO;
	
	@Autowired
	private DumpOrderHbaseDAO dumpOrderHbaseDAO;
	
	@Autowired
	RiskTradeTypeMysqlDAO riskTradeTypeMysqlDAO;
	
	@Autowired
	UserAmountCollectMysqlDAO userAmountCollectMysqlDAO;
	
	@Autowired
	RiskTradeTypeService riskTradeTypeService;
	
	@Autowired
	PayFlowMysqlDAO payFlowMysqlDAO;
	
	@Autowired
	private DubboClientFactory dubboConsumerFactory;
	
	@Override
	@SlaveQueryAnnotation
	public OrderB2C findOneB2C(QueryOrderRequest request) {
		QueryOrder query = new QueryOrder();
		PageQuery pageQuery = new PageQuery(1, 1);
		OrderB2C result = null;
		if (request != null) {
			BeanUtils.copyProperties(request, query);
			handleOrderB2CQuery(query);
		}
		List<OrderB2cDO> orderB2cList = treadQueryService.B2CQuery(query, pageQuery);

		for (OrderB2cDO orderB2c : orderB2cList) {
			if (orderB2c != null) {
				result = renderOrderB2C(orderB2c);
				break;
			}
		}
		return result;
	}

	@Override
	@SlaveQueryAnnotation
	public int findB2CCount(QueryOrderRequest request) {
		QueryOrder query = new QueryOrder();
		if (request != null) {
			BeanUtils.copyProperties(request, query);
			handleOrderB2CQuery(query);
		}
		return treadQueryService.B2CTotalCount(query);
	}

	@Override
	@SlaveQueryAnnotation
	public OrderB2CList findB2C(QueryOrderRequest request, Integer pageNo, Integer pageSize) {
		QueryOrder query = new QueryOrder();
		PageQuery pageQuery = pageNo == -1 ? null : new PageQuery(pageNo, pageSize, pageSize);
		OrderB2CList orderB2CList = new OrderB2CList();
		List<OrderB2C> orderB2Cs = new ArrayList<OrderB2C>();
		if (request != null) {
			BeanUtils.copyProperties(request, query);
			handleOrderB2CQuery(query);
		}
		Integer totalCount = treadQueryService.B2CTotalCount(query);
		List<OrderB2cDO> orderB2cDOList = null;
		if(totalCount > 0){
			orderB2cDOList = treadQueryService.B2CQuery(query, pageQuery);
			for (OrderB2cDO orderB2c : orderB2cDOList) {
				if (orderB2c != null) {
					orderB2Cs.add(renderOrderB2C(orderB2c));
				}
			}
		}
		orderB2CList.setRows(orderB2Cs);
		orderB2CList.setTotal(totalCount);
		return orderB2CList;
	}

	@Override
	@SlaveQueryAnnotation
	public OrderRecharge findOneRecharge(QueryOrderRequest request) {
		QueryOrder query = new QueryOrder();
		PageQuery pageQuery = new PageQuery(1, 1);
		OrderRecharge result = null;
		if (request != null) {
			BeanUtils.copyProperties(request, query);
			handleOrderB2CQuery(query);
		}
		List<OrderRechargeDO> orderRechargeList = treadQueryService.rechargeQuery(query, pageQuery);
		for (OrderRechargeDO orderRecharge : orderRechargeList) {
			if (orderRecharge != null) {
				result = renderOrderRecharge(orderRecharge);
				break;
			}
		}
		return result;
	}

	@Override
	@SlaveQueryAnnotation
	public int findRechargeCount(QueryOrderRequest request) {
		QueryOrder query = new QueryOrder();
		if (request != null) {
			BeanUtils.copyProperties(request, query);
			handleOrderB2CQuery(query);
		}
		return treadQueryService.rechargeTotalCount(query);
	}

	@Override
	@SlaveQueryAnnotation
	public OrderRechargeList findRecharge(QueryOrderRequest request, Integer pageNo, Integer pageSize) {
		QueryOrder query = new QueryOrder();
		PageQuery pageQuery = pageNo == -1 ? null : new PageQuery(pageNo, pageSize, pageSize);
		OrderRechargeList orderRechargeList = new OrderRechargeList();
		List<OrderRecharge> orderRecharges = new ArrayList<OrderRecharge>();
		if (request != null) {
			BeanUtils.copyProperties(request, query);
			handleOrderB2CQuery(query);
		}
		Integer totalCount = treadQueryService.rechargeTotalCount(query);
		List<OrderRechargeDO> orderRechargeDOList = null;
		if(totalCount > 0){
			orderRechargeDOList = treadQueryService.rechargeQuery(query, pageQuery);
			for (OrderRechargeDO orderRechargeDO : orderRechargeDOList) {
				if (orderRechargeDO != null) {
					OrderRecharge orderRecharge = renderOrderRecharge(orderRechargeDO);
					orderRecharges.add(orderRecharge);
				}
			}
		}
		orderRechargeList.setRows(orderRecharges);
		orderRechargeList.setTotal(totalCount);
		return orderRechargeList;
	}

	@Override
	@SlaveQueryAnnotation
	public OrderRefund findOneRefund(QueryOrderRequest request) {
		QueryOrder query = new QueryOrder();
		PageQuery pageQuery = new PageQuery(1, 1);
		OrderRefund result = null;
		if (request != null) {
			BeanUtils.copyProperties(request, query);
			handleOrderB2CQuery(query);
		}
		List<OrderRefundDO> orderRefundList = treadQueryService.refundQuery(query, pageQuery);
		for (OrderRefundDO orderRefund : orderRefundList) {
			if (orderRefund != null) {
				result = renderOrderRefund(orderRefund);
				break;
			}
		}
		return result;
	}

	@Override
	@SlaveQueryAnnotation
	public int findRefundCount(QueryOrderRequest request) {
		QueryOrder query = new QueryOrder();
		if (request != null) {
			BeanUtils.copyProperties(request, query);
			handleOrderB2CQuery(query);
		}
		return treadQueryService.refundTotalCount(query);
	}

	@Override
	@SlaveQueryAnnotation
	public OrderRefundList findRefund(QueryOrderRequest request, Integer pageNo, Integer pageSize) {
		QueryOrder query = new QueryOrder();
		PageQuery pageQuery = pageNo == -1 ? null : new PageQuery(pageNo, pageSize, pageSize);
		List<OrderRefund> orderRefunds = new ArrayList<OrderRefund>();
		OrderRefundList orderRefundList = new OrderRefundList();
		if (request != null) {
			BeanUtils.copyProperties(request, query);
			handleOrderB2CQuery(query);
		}
		Integer totalCount = treadQueryService.refundTotalCount(query);
		List<OrderRefundDO> orderRefundDOList = null;
		if(totalCount > 0){
			orderRefundDOList = treadQueryService.refundQuery(query, pageQuery);
			for (OrderRefundDO orderRefundDO : orderRefundDOList) {
				if (orderRefundDO != null) {
					OrderRefund result = renderOrderRefund(orderRefundDO);
					orderRefunds.add(result);
				}
			}
		}
		orderRefundList.setRows(orderRefunds);
		orderRefundList.setTotal(totalCount);
		return orderRefundList;
	}

	@Override
	@SlaveQueryAnnotation
	public OrderTransfer findOneTransfer(QueryOrderRequest request) {
		QueryOrder query = new QueryOrder();
		PageQuery pageQuery = new PageQuery(1, 1);
		OrderTransfer result = null;
		if (request != null) {
			BeanUtils.copyProperties(request, query);
			handleOrderB2CQuery(query);
		}
		List<OrderTransferDO> orderTransferList = treadQueryService.transferQuery(query, pageQuery);
		for (OrderTransferDO OrderTransfer : orderTransferList) {
			if (OrderTransfer != null) {
				result = renderOrderTransfer(OrderTransfer);
				break;
			}
		}
		return result;
	}

	@Override
	@SlaveQueryAnnotation
	public int findTransferCount(QueryOrderRequest request) {
		QueryOrder query = new QueryOrder();
		if (request != null) {
			BeanUtils.copyProperties(request, query);
			handleOrderB2CQuery(query);
		}
		return treadQueryService.transferTotalCount(query);
	}

	@Override
	@SlaveQueryAnnotation
	public OrderTransferList findTransfer(QueryOrderRequest request, Integer pageNo, Integer pageSize) {
		QueryOrder query = new QueryOrder();
		PageQuery pageQuery = pageNo == -1 ? null : new PageQuery(pageNo, pageSize, pageSize);
		List<OrderTransfer> orderTransfers = new ArrayList<OrderTransfer>();
		OrderTransferList orderTransferList = new OrderTransferList();
		if (request != null) {
			BeanUtils.copyProperties(request, query);
			handleOrderB2CQuery(query);
		}
		Integer totalCount = treadQueryService.transferTotalCount(query);
		List<OrderTransferDO> orderTransferDOList = null;
		if(totalCount > 0){
			orderTransferDOList = treadQueryService.transferQuery(query, pageQuery);
			for (OrderTransferDO orderTransferDO : orderTransferDOList) {
				if (orderTransferDO != null) {
					OrderTransfer orderTransfer = renderOrderTransfer(orderTransferDO);
					orderTransfers.add(orderTransfer);
				}
			}
		}
		orderTransferList.setRows(orderTransfers);
		orderTransferList.setTotal(totalCount);
		return orderTransferList;
	}

	@Override
	@SlaveQueryAnnotation
	public OrderWithdraw findOneWithdraw(QueryOrderRequest request) {
		QueryOrder query = new QueryOrder();
		PageQuery pageQuery = new PageQuery(1, 1);
		OrderWithdraw result = null;
		if (request != null) {
			BeanUtils.copyProperties(request, query);
			handleOrderB2CQuery(query);
		}
		List<OrderWithdrawDO> withdrawQueryList = treadQueryService.withdrawQuery(enCodeWithDrawOrderQuery(query), pageQuery);
		for (OrderWithdrawDO orderWithdraw : withdrawQueryList) {
			if (orderWithdraw != null) {
				result = renderOrderWithdraw(orderWithdraw);
				break;
			}
		}
		return result;
	}

	@Override
	@SlaveQueryAnnotation
	public int findWithdrawCount(QueryOrderRequest request) {
		QueryOrder query = new QueryOrder();
		if (request != null) {
			BeanUtils.copyProperties(request, query);
			handleOrderB2CQuery(query);
			query = enCodeWithDrawOrderQuery(query);
		}
		return treadQueryService.withdrawTotalCount(query);
	}

	@Override
	@SlaveQueryAnnotation
	public OrderWithdrawList findWithdraw(QueryOrderRequest request, Integer pageNo, Integer pageSize) {
		QueryOrder query = new QueryOrder();
		PageQuery pageQuery = pageNo == -1 ? null : new PageQuery(pageNo, pageSize, pageSize);
		List<OrderWithdraw> orderWithdraws = new ArrayList<OrderWithdraw>();
		OrderWithdrawList orderWithdrawList = new OrderWithdrawList();
		if (request != null) {
			BeanUtils.copyProperties(request, query);
			handleOrderB2CQuery(query);
			query = enCodeWithDrawOrderQuery(query);
		}
		Integer totalCount = treadQueryService.withdrawTotalCount(query);
		List<OrderWithdrawDO> withdrawQueryDOList = null;
		if(totalCount > 0){
			withdrawQueryDOList = treadQueryService.withdrawQuery(query, pageQuery);
			for (OrderWithdrawDO orderWithdrawDO : withdrawQueryDOList) {
				if (orderWithdrawDO != null) {
					OrderWithdraw orderWithdraw = renderOrderWithdraw(orderWithdrawDO);
					orderWithdraws.add(orderWithdraw);
				}
			}
		}
		orderWithdrawList.setRows(orderWithdraws);
		orderWithdrawList.setTotal(totalCount);
		return orderWithdrawList;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	@SlaveQueryAnnotation
	public PayFlowList findPayFlow(QueryOrderRequest request, Integer pageNo, Integer pageSize) {
		QueryOrder query = new QueryOrder();
		PageQuery pageQuery = pageNo == -1 ? null : new PageQuery(pageNo, pageSize);
		List<PayFlow> payFlows = new ArrayList();
		PayFlowList payFlowResponse = new PayFlowList();

		// 先对入参进行有效性验证
		if (request == null || request.getTradeOrderId() == null || "".equals(request.getTradeOrderId())) {
			return payFlowResponse;
		}
		payFlowResponse.setPageNo(pageNo);
		payFlowResponse.setPageSize(pageSize);

		if (request != null) {
			BeanUtils.copyProperties(request, query);
			handleOrderB2CQuery(query);
		}
		List<OrderMappingDO> orderMappings = treadQueryService.orderMappingQuery(query, null);
		List<String> tradeOrderIds = new ArrayList();
		tradeOrderIds.add(query.getTradeOrderId());
		if (orderMappings != null && orderMappings.size() > 0) {
			for (OrderMappingDO orderMapping : orderMappings)
				tradeOrderIds.add(orderMapping.getMappingOrderId());
		}
		Integer totalCount = treadQueryService.payFlowCount(query.getTradeOrderId(), tradeOrderIds);

		if (totalCount != null && totalCount > 0) {
			List<PayFlowDO> payFlowDOs = treadQueryService.payFlowQuery(query.getTradeOrderId(), tradeOrderIds, pageQuery);
			if (payFlowDOs != null && payFlowDOs.size() > 0)
				for (PayFlowDO payFlowDO : payFlowDOs) {
					PayFlow payFlow = renderPayFlow(payFlowDO);
					payFlows.add(payFlow);
				}
		}
		payFlowResponse.setTotal(totalCount == null ? 0 : totalCount);
		payFlowResponse.setRows(payFlows);
		return payFlowResponse;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	@SlaveQueryAnnotation
	public OrderCallbackList findOrderCallback(QueryOrderCallback request, Integer pageNo, Integer pageSize) {
		QueryCallback query = new QueryCallback();
		PageQuery pageQuery = pageNo == -1 ? null : new PageQuery(pageNo, pageSize);
		List<OrderCallback> orderCallbacks = new ArrayList();
		OrderCallbackList orderCallbackList = new OrderCallbackList();

		// 先对入参进行有效性验证,可以以后对这个入参进行扩展，比如为属性加注解进行通用验证
		if (request == null || request.getOrderId() == null || "".equals(request.getOrderId())) {
			return orderCallbackList;
		}
		orderCallbackList.setPageNo(pageNo);
		orderCallbackList.setPageSize(pageSize);

		if (request != null) {
			BeanUtils.copyProperties(request, query);
		}

		Integer totalCount = callBackService.countOrderCallBack(query);

		if (totalCount != null && totalCount > 0) {
			List<CallbackNotifyDO> callbackNotifyDOs = callBackService.queryOrderCallBack(query, pageQuery);
			if (callbackNotifyDOs != null && callbackNotifyDOs.size() > 0)
				for (CallbackNotifyDO notifyDO : callbackNotifyDOs) {
					OrderCallback orderCallback = renderOrderCallback(notifyDO);
					orderCallbacks.add(orderCallback);
				}
		}
		orderCallbackList.setTotal(totalCount == null ? 0 : totalCount);
		orderCallbackList.setRows(orderCallbacks);
		return orderCallbackList;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	@SlaveQueryAnnotation
	public OrderSettleList findSettleOrder(QueryOrderSettle request, Integer pageNo, Integer pageSize) {
		QuerySettle query = new QuerySettle();
		PageQuery pageQuery = pageNo == -1 ? null : new PageQuery(pageNo, pageSize);
		List<OrderSettle> settleOrders = new ArrayList();
		OrderSettleList settleOrderList = new OrderSettleList();

		// 先对入参进行有效性验证,可以以后对这个入参进行扩展，比如为属性加注解进行通用验证
		if (request == null || request.getOrderId() == null || "".equals(request.getOrderId())) {
			return settleOrderList;
		}
		settleOrderList.setPageNo(pageNo);
		settleOrderList.setPageSize(pageSize);

		if (request != null) {
			BeanUtils.copyProperties(request, query);
		}

		Integer totalCount = settleService.countOrderSettle(query);

		if (totalCount != null && totalCount > 0) {
			List<SettleOrderDO> settleOrderDOs = settleService.queryOrderSettle(query, pageQuery);
			if (settleOrderDOs != null && settleOrderDOs.size() > 0)
				for (SettleOrderDO settleOrderDO : settleOrderDOs) {
					OrderSettle settleOrder = renderOrderSettle(settleOrderDO);
					settleOrders.add(settleOrder);
				}
		}
		settleOrderList.setTotal(totalCount == null ? 0 : totalCount);
		settleOrderList.setRows(settleOrders);
		return settleOrderList;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	@SlaveQueryAnnotation
	public UserActFlowList findAccountFlow(QueryUserAccountFlow request,
			Integer pageNo, Integer pageSize) {
		UserActFlowDO query = new UserActFlowDO();
		PageQuery pageQuery = pageNo == -1 ? null : new PageQuery(pageNo, pageSize);
		List<UserActFlow> userActFlows = new ArrayList();
		UserActFlowList userActFlowList = new UserActFlowList();

		userActFlowList.setPageNo(pageNo);
		userActFlowList.setPageSize(pageSize);

		if (request != null) {
			BeanUtils.copyProperties(request, query);
		}

		Integer totalCount = userActFlowMysqlDAO.listCount(query);

		if (totalCount != null && totalCount > 0) {
			List<UserActFlowDO> userActFlowDOs = userActFlowMysqlDAO.listPage(query, pageQuery);
			if (userActFlowDOs != null && userActFlowDOs.size() > 0)
				for (UserActFlowDO userActFlowDO : userActFlowDOs) {
					UserActFlow userActFlow = renderAccountFlow(userActFlowDO);
					userActFlows.add(userActFlow);
				}
		}
		userActFlowList.setTotal(totalCount == null ? 0 : totalCount);
		userActFlowList.setRows(userActFlows);
		return userActFlowList;
	}

	@Override
	@SlaveQueryAnnotation
	public OrderRefundList findB2CRefundDetail(String tradeOrderNo) {
		List<OrderRefund> orderRefunds = new ArrayList<OrderRefund>();
		OrderRefundList orderRefundList = new OrderRefundList();

		List<OrderRefundDO> orderRefundDOList = orderRefundMysqlDAO.findBySrcOrderId(tradeOrderNo);
		for (OrderRefundDO orderRefundDO : orderRefundDOList) {
			if (orderRefundDO != null) {
				OrderRefund result = renderOrderRefund(orderRefundDO);
				orderRefunds.add(result);
			}
		}
		
		orderRefundList.setRows(orderRefunds);
		Integer totalCount = orderRefundDOList == null ? 0 : orderRefundDOList.size();
		orderRefundList.setTotal(totalCount);
		return orderRefundList;
	}

	// 提现的实体里有部分加密字段在此解密 
	private String deCodeMessage(String message){
		if(StringUtil.isNotBlank(message)){
			try {
				return YHBFUtil.decrypt(message);
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return message;
	}
	
	// 提现的实体里有部分加密字段在此加密
	private QueryOrder enCodeWithDrawOrderQuery(QueryOrder query){
		try {
			if(StringUtil.isNotBlank(query.getPayeeAccountId())){
				query.setPayeeAccountId(YHBFUtil.encrypt(query.getPayeeAccountId()));
			}
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return query;
	}
	
	/*====================== 实体转换 ==========================*/
	private static final String DEFAULTTYPE = "未知";
	private static final String DEFAULWITHTTYPE = "提现到余额";
	
	private OrderB2C renderOrderB2C(OrderB2cDO order){
		if(order == null) return null;
		OrderB2C result = new OrderB2C();
		BeanUtils.copyProperties(order, result);
		result.setOrderStatus(order.getOrderStatus() != null ? String.valueOf(order.getOrderStatus()) : null);
		// 自定义处理
		result.setGuaranteeTypeStr(getB2CGuaranteeTypeStr(order.getGuaranteeType()));
		Constance.TradeOrderType orderType = Constance.TradeOrderType.valueOf(order.getOrderType() == null ? -1:order.getOrderType());
		result.setOrderTypeStr(orderType == null ? DEFAULTTYPE : orderType.getDesc());
		Constance.B2COrderState b2cOrderState = Constance.B2COrderState.valueOf(order.getOrderStatus() == null ? -1:order.getOrderStatus());
		result.setOrderStatusStr(b2cOrderState == null ? DEFAULTTYPE : b2cOrderState.getDesc());
		result.setInnerStatusStr(getInnerStatusStr(order.getInnerStatus() == null ? -1:order.getInnerStatus()));
		result.setChannelTypeStr(getB2COrderChannelStr(order.getOrderChannel()));
//		Constance.PayType payType = Constance.PayType.valueOf(order.getPayType() == null ? -1:order.getPayType());
//		result.setPayTypeStr(payType == null ? getpayTypeByBankId(order.getPayBankId()) : payType.getDesc());
		result.setPayTypeStr(getpayTypeByBankId(order.getPayBankId()));
		result.setOrderChannelStr(getB2COrderChannelStr(order.getOrderChannel()));
		result.setProductTypeStr(getB2CProductTypeStr(order.getProductType()));
		result.setBusinessTypeDes(getBusinessTypeDesc(result.getBusinessType()));
		result.setTradeAmount(CurrencyUtil.fen2yuan(order.getTradeAmount()));
		result.setPayAmount(CurrencyUtil.fen2yuan(order.getPayAmount()));
		result.setFee(CurrencyUtil.fen2yuan(order.getFee()));
		result.setPlatChannelIdDesc(getPlatChannelIdDesc(order.getPlatChannelId()));
		
		result.setRefundAmount(CurrencyUtil.fen2yuan(order.getRefundAmount()));
		return result;
	}
	
	private String getPlatChannelIdDesc(String platChannelId) {
		if (StringUtils.isEmpty(platChannelId)){
			return "未知";
		} else  if (platChannelId.equals("99")) {
			return "缴费";
		}
		return "商城";
	}

	private String getBusinessTypeDesc(String businessType){
		RiskTradeTypeDO riskTradeTypeDOById = riskTradeTypeService.getRiskTradeTypeDOById(businessType);
		return riskTradeTypeDOById.getTradeTypeName();
	}
	
	private OrderRecharge renderOrderRecharge(OrderRechargeDO order){
		if(order == null) return null;
		OrderRecharge result = new OrderRecharge();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		Constance.ChargeOrderState rechargeStatus = Constance.ChargeOrderState.valueOf(order.getOrderStatus() == null ? -1:order.getOrderStatus());
		result.setRechargeStatusStr(rechargeStatus == null ? DEFAULTTYPE : rechargeStatus.getDesc());
//		Constance.PayType payType = Constance.PayType.valueOf(order.getPayType() == null ? -1:order.getPayType());
//		result.setPayTypeStr(payType == null ?  getpayTypeByBankId(order.getPayBankId()) : payType.getDesc());
		result.setPayTypeStr(getpayTypeByBankId(order.getPayBankId()));
		result.setRechargeChannelStr(getRECRechargeChannelStr(order.getRechargeChannel() == null ? -1:order.getRechargeChannel()));
		result.setInnerStatusStr(getInnerStatusStr(order.getInnerStatus() == null ? -1:order.getInnerStatus()));
		Constance.CardActType bankCardActType = Constance.CardActType.valueOf(order.getBankCardActType() == null ? -1 : order.getBankCardActType());
		result.setBankCardActType(bankCardActType == null ? DEFAULTTYPE : bankCardActType.getDesc());
		Constance.CardType bankCardType = Constance.CardType.valueOf(order.getBankCardType() == null ? -1 : order.getBankCardType());
		result.setBankCardType(bankCardType == null ? DEFAULTTYPE : bankCardType.getDesc());
		result.setBusinessTypeDes(getBusinessTypeDesc(result.getBusinessType()));
		result.setRechargeAmount(CurrencyUtil.fen2yuan(order.getRechargeAmount()));
		result.setRechargeFee(CurrencyUtil.fen2yuan(order.getRechargeFee()));
		result.setPayAmount(CurrencyUtil.fen2yuan(order.getPayAmount()));
		result.setPlatChannelIdDesc(getPlatChannelIdDesc(order.getPlatChannelId()));
		result.setBankCardNo(YHBFSensitiveEnc.sensitiveDec(order.getBankCardNo(), "cardno"));
		return result;
	}
	
	private OrderRefund renderOrderRefund(OrderRefundDO order){
		if(order == null) return null;
		OrderRefund result = new OrderRefund();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		Constance.RefundType refundType = Constance.RefundType.valueOf(order.getRefundType() == null ? -1:order.getRefundType());
		result.setRefundTypeStr(refundType == null ? DEFAULTTYPE : refundType.getDesc());
		Constance.RefundOrderState refundStatus = Constance.RefundOrderState.valueOf(order.getOrderStatus() == null ? -1:order.getOrderStatus());
		result.setRefundStatusStr(refundStatus == null ? DEFAULTTYPE : refundStatus.getDesc());
		result.setRefundChannelStr(getRECRechargeChannelStr(order.getRefundChannel() == null ? -1:order.getRefundChannel()));
		result.setInnerStatusStr(getInnerStatusStr(order.getInnerStatus() == null ? -1:order.getInnerStatus()));
		result.setBusinessTypeDes(getBusinessTypeDesc(result.getBusinessType()));
		result.setRefundAmount(CurrencyUtil.fen2yuan(order.getRefundAmount()));
		result.setRefundFee(CurrencyUtil.fen2yuan(order.getRefundFee()));
		result.setPayAmount(CurrencyUtil.fen2yuan(order.getPayAmount()));
		result.setPlatChannelIdDesc(getPlatChannelIdDesc(order.getPlatChannelId()));
		return result;
	}
	
	private OrderTransfer renderOrderTransfer(OrderTransferDO order){
		if(order == null) return null;
		OrderTransfer result = new OrderTransfer();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		Constance.TransferType transferType = Constance.TransferType.valueOf(order.getTransferType() == null ? -1:order.getTransferType());
		result.setTransferTypeStr(transferType == null ? DEFAULTTYPE : transferType.getDesc());
		Constance.TransferOrderState transferStatus = Constance.TransferOrderState.valueOf(order.getOrderStatus() == null ? -1:order.getOrderStatus());
		result.setTransferStatusStr(transferStatus == null ? DEFAULTTYPE : transferStatus.getDesc());
		result.setTransferChannelStr(getRECRechargeChannelStr(order.getTransferChannel() == null ? -1:order.getTransferChannel()));
		result.setInnerStatusStr(getInnerStatusStr(order.getInnerStatus() == null ? -1:order.getInnerStatus()));
		Constance.CardActType cardactType = Constance.CardActType.valueOf(order.getPayeeCardActType() == null ? -1:order.getPayeeCardActType());
		result.setCardactTypeStr(cardactType == null ? DEFAULTTYPE : cardactType.getDesc());
		Constance.BaseBusinessStatus busniessStatus = Constance.BaseBusinessStatus.valueOf(order.getBusniessStatus());
		result.setBusniessStatusStr(busniessStatus == null ? DEFAULTTYPE : busniessStatus.getDesc());
		Constance.TradeIfUserPwd ifUserPwd = Constance.TradeIfUserPwd.valueOf(order.getIsUsePwd());
		result.setIsUsePwdStr(ifUserPwd == null ? DEFAULTTYPE : ifUserPwd.getDesc());
		Constance.TransferBusinessID busniessStr = Constance.TransferBusinessID.valueOf(order.getBusniessId());
		result.setBusniessId(busniessStr == null ? DEFAULTTYPE : busniessStr.getDesc());
		result.setBusinessTypeDes(getBusinessTypeDesc(result.getBusinessType()));
		result.setTransferAmount(CurrencyUtil.fen2yuan(order.getTransferAmount()));
		result.setTransferFee(CurrencyUtil.fen2yuan(order.getTransferFee()));
		result.setPayAmount(CurrencyUtil.fen2yuan(order.getPayAmount()));
		result.setPlatChannelIdDesc(getPlatChannelIdDesc(order.getPlatChannelId()));
		result.setCardNo(deCodeMessage(order.getPayeeCardNo()));
		return result;
	}
	
	private OrderWithdraw renderOrderWithdraw(OrderWithdrawDO order){
		if(order == null) return null;
		OrderWithdraw result = new OrderWithdraw();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		Constance.WithDrawType withdrawType = Constance.WithDrawType.valueOf(order.getWithdrawType() == null ? -1:order.getWithdrawType());
		result.setWithdrawTypeStr(withdrawType == null ? DEFAULTTYPE : withdrawType.getDesc());
		Constance.WithdrawState withdrawStatus = Constance.WithdrawState.valueOf(order.getOrderStatus() == null ? -1:order.getOrderStatus());
		result.setWithdrawStatusStr(withdrawStatus == null ? DEFAULTTYPE : withdrawStatus.getDesc());
		result.setWithdrawChannelStr(getRECRechargeChannelStr(order.getWithdrawChannel() == null ? -1:order.getWithdrawChannel()));
		result.setInnerStatusStr(getInnerStatusStr(order.getInnerStatus() == null ? -1:order.getInnerStatus()));
		result.setVerifyTypeStr(getWDVerifyTypeStr(order.getVerifyType() == null ? -1:order.getVerifyType()));
		Constance.BaseBusinessStatus busniessStatus = Constance.BaseBusinessStatus.valueOf(order.getBusniessStatus());
		result.setBusniessStatusStr(busniessStatus == null ? DEFAULTTYPE : busniessStatus.getDesc());
		Constance.WithdrawWay withdrawWay = Constance.WithdrawWay.valueOf(order.getWithdrawWay() == null ? -1:Integer.parseInt(order.getWithdrawWay()));
		result.setWithdrawWay(withdrawWay == null ? DEFAULWITHTTYPE : withdrawWay.getDesc());
		result.setBusinessTypeDes(getBusinessTypeDesc(result.getBusinessType()));
		result.setWithdrawAmount(CurrencyUtil.fen2yuan(order.getWithdrawAmount()));
		result.setWithdrawFee(CurrencyUtil.fen2yuan(order.getWithdrawFee()));
		result.setPayAmount(CurrencyUtil.fen2yuan(order.getPayAmount()));
		result.setPlatChannelIdDesc(getPlatChannelIdDesc(order.getPlatChannelId()));
		LOG.info("Order WithdrawCardNo is {}", order.getWithdrawCardNo());
		result.setWithdrawCardNo(YHBFSensitiveEnc.sensitiveDec(order.getWithdrawCardNo(), "cardno"));
		return result;
	}
	
	private PayFlow renderPayFlow(PayFlowDO order){
		if(order == null) return null;
		PayFlow result = new PayFlow();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		Constance.UserType payerUserType = Constance.UserType.valueOf(order.getPayerUserType() == null ? -1:order.getPayerUserType());
		result.setPayerUserTypeStr(payerUserType == null ? DEFAULTTYPE : payerUserType.getDesc());
		Constance.UserActType payerActType = Constance.UserActType.valueOf(order.getPayerActType() == null ? -1:order.getPayerActType());
		result.setPayerActTypeStr(payerActType == null ? DEFAULTTYPE : payerActType.getDesc());
		Constance.CardType payerCardType = Constance.CardType.valueOf(order.getPayerCardType() == null ? -1:order.getPayerCardType());
		result.setPayerCardTypeStr(payerCardType == null ? DEFAULTTYPE : payerCardType.getDesc());
		result.setPayerCardActTypeStr(getPayFlowPayerCardActTypeStr(order.getPayerCardActType() == null ? -1:order.getPayerCardActType()));
		Constance.IdCardType identityType = Constance.IdCardType.valueOf(order.getPayerIdentityType() == null ? -1:order.getPayerIdentityType());
		result.setPayerIdentityTypeStr(identityType == null ? DEFAULTTYPE : identityType.getDesc());
		Constance.UserType payeeUserType = Constance.UserType.valueOf(order.getPayeeUserType() == null ? -1:order.getPayeeUserType());
		result.setPayeeUserTypeStr(payeeUserType == null ? DEFAULTTYPE : payeeUserType.getDesc());
		Constance.UserActType payeeActType = Constance.UserActType.valueOf(order.getPayeeActType() == null ? -1:order.getPayeeActType());
		result.setPayeeActTypeStr(payeeActType == null ? DEFAULTTYPE : payeeActType.getDesc());
		result.setPayeeCardActTypeStr(getPayFlowPayerCardActTypeStr(order.getPayerActType() == null ? -1:order.getPayerActType()));
		Constance.PayFlowType payType = Constance.PayFlowType.valueOf(order.getPayType() == null ? -1:order.getPayType());
		result.setPayTypeStr(payType == null ? DEFAULTTYPE : payType.getDesc());
		Constance.TradeOrderType orderType = Constance.TradeOrderType.valueOf(order.getTradeOrderType() == null ? -1:order.getTradeOrderType());
		result.setTradeOrderTypeStr(orderType == null ? DEFAULTTYPE : orderType.getDesc());
		Constance.PayFlowState payStatus = Constance.PayFlowState.valueOf(order.getPayStatus() == null ? -1:order.getPayStatus());
		result.setPayStatusStr(payStatus == null ? DEFAULTTYPE : payStatus.getDesc());
		result.setHandleStatusStr(getPayFlowHandleStatusStr(order.getHandleStatus()));
		
		result.setAmount(CurrencyUtil.fen2yuan(order.getAmount()));
		
		result.setPayerBankAct(deCodeMessage(order.getPayerBankAct()));
		result.setPayerIdentityNo(deCodeMessage(order.getPayerIdentityNo()));
		result.setPayerMobile(deCodeMessage(order.getPayerMobile()));
		result.setPayeeBankAct(deCodeMessage(order.getPayeeBankAct()));
		result.setPayeeActNo(YHBFSensitiveEnc.sensitiveDec(order.getPayeeActNo(), "cardno"));
		return result;
	}

	private OrderCallback renderOrderCallback(CallbackNotifyDO order){
		if(order ==null) return null;
		OrderCallback result = new OrderCallback();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		Constance.NotifyState status = Constance.NotifyState.valueOf(order.getStatus() == null ? -1:order.getStatus());
		result.setStatusStr(status == null ? DEFAULTTYPE : status.getDesc());
		Constance.CallBackOrderState orderStatus = Constance.CallBackOrderState.valueOf(order.getOrderStatus() == null ? -1:order.getOrderStatus());
		result.setOrderStatusStr(orderStatus == null ? DEFAULTTYPE : orderStatus.getDesc());
		Constance.TradeOrderType orderType = Constance.TradeOrderType.valueOf(order.getOrderType() == null ? -1:order.getOrderType());
		result.setOrderTypeStr(orderType == null ? DEFAULTTYPE : orderType.getDesc());
		
		result.setTotalFee(CurrencyUtil.fen2yuan(order.getTotalFee()));
		result.setPayAmount(CurrencyUtil.fen2yuan(order.getPayAmount()));
		return result;
	}

	private OrderSettle renderOrderSettle(SettleOrderDO order){
		if(order ==null) return null;
		OrderSettle result = new OrderSettle();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		Constance.OrderSettleType settleType = Constance.OrderSettleType.valueOf(order.getSettleType());
		result.setSettleTypeStr(settleType == null ? DEFAULTTYPE : settleType.getDesc());
		Constance.OrderSettleState state = Constance.OrderSettleState.valueOf(order.getState());
		result.setStateStr(state == null ? DEFAULTTYPE : state.getDesc());
		
		result.setSettleAmount(CurrencyUtil.fen2yuan(order.getSettleAmount()));
		result.setHandlingFee(CurrencyUtil.fen2yuan(order.getHandlingFee()));
		result.setFundsToAccount(CurrencyUtil.fen2yuan(order.getFundsToAccount()));
		return result;
	}

	private UserActFlow renderAccountFlow(UserActFlowDO order){
		if(order ==null) return null;
		UserActFlow result = new UserActFlow();
		BeanUtils.copyProperties(order, result);
		// 自定义处理
		Constance.UserActType actType = Constance.UserActType.valueOf(order.getActType() == null ? -1:order.getActType());
		result.setActTypeStr(actType == null ? DEFAULTTYPE : actType.getDesc());
		Constance.TradeOrderType orderType = Constance.TradeOrderType.valueOf(order.getTradeType()== null ? -1:order.getTradeType());
		result.setTradeTypeStr(orderType == null ? DEFAULTTYPE : orderType.getDesc());
		
		result.setActBalance(CurrencyUtil.fen2yuan(order.getActBalance()));
		result.setTranAmount(CurrencyUtil.fen2yuan(order.getTranAmount()));
		return result;
	}

	/*====================== /实体转换 ==========================*/

	/*====================== 一些小方法 ==========================*/
	private String getB2CGuaranteeTypeStr(Integer guaranteeType){
		if(guaranteeType == 0)
			return "及时";
		else if(guaranteeType == 1)
			return "担保";
		else
			return DEFAULTTYPE;
	}
	private String getInnerStatusStr(Integer innerStatus){
		if(innerStatus == 0)
			return "正常";
		else if(innerStatus == 1)
			return "作废";
		else
			return DEFAULTTYPE;
	}
	private String getB2COrderChannelStr(Integer orderChannel){
		if(orderChannel == 1)
			return "网站";
		else if(orderChannel == 2)
			return "手机";
		else if(orderChannel == 3)
			return "微信";
		else
			return DEFAULTTYPE;
	}
	private String getB2CProductTypeStr(Integer productType){
		if(productType == 1)
			return "实物";
		else if(productType == 2)
			return "虚拟";
		else
			return DEFAULTTYPE;
	}
	private String getRECRechargeChannelStr(Byte rechargeChannel){
		if(rechargeChannel == 1)
			return "网站";
		else if(rechargeChannel == 2)
			return "手机";
		else if(rechargeChannel == 3)
			return "微信";
		else if(rechargeChannel == 4)
			return "内部";
		else
			return DEFAULTTYPE;
	}
	private String getWDVerifyTypeStr(Byte verifyType){
		if(verifyType == 0)
			return "无需审批";
		else if(verifyType == 1)
			return "需要审批";
		else
			return DEFAULTTYPE;
	}
	private String getPayFlowHandleStatusStr(int handleStatus){
		if(handleStatus == 0)
			return "未处理";
		else if(handleStatus == 1)
			return "已处理";
		else
			return DEFAULTTYPE;
	}
	private String getPayFlowPayerCardActTypeStr(Integer payerActType){
		if(payerActType == 1)
			return "对私账户";
		else if(payerActType == 2)
			return "对公账户";
		else
			return DEFAULTTYPE;
	}
	private String getpayTypeByBankId(String bankId){
		if(StringUtil.isBlank(bankId)) return DEFAULTTYPE;
		if(bankId.startsWith("0"))
			return "余额支付";
		else if(bankId.startsWith("1"))
			return "网银支付";
		else if(bankId.startsWith("2"))
			return "快捷支付";
		else if(bankId.startsWith("3")){
			if(("3000000").equals(bankId))
				return "支付宝WAP支付";
			else if(("3000001").equals(bankId))
				return "微信公众号支付";
			else if(("3000002").equals(bankId))
				return "微信APP支付";
			else  if(("3000003").equals(bankId))
				return "微信APP支付(ios)";
			else  if(("3000004").equals(bankId))
				return "支付宝扫码";
			else  if(("3000005").equals(bankId))
				return "微信扫码";
			else  if(("3000006").equals(bankId))
				return "微信反扫码";
			else  if(("3000007").equals(bankId))
				return "支付宝反扫码";
			else 
				return DEFAULTTYPE;
		} else if(bankId.startsWith("4"))
			return "转帐支付类型";
		else if(bankId.startsWith("5"))
			return "提现";
		else if(bankId.startsWith("6"))
			return "代发到银行";
		else if(bankId.startsWith("7"))
			return "代发到第三方支付账户";
		else
			return DEFAULTTYPE;
	}
	
	//处理订单查询条件中的复合条件
	private void handleOrderB2CQuery(QueryOrder query){
		if(null == query) return;
		if(StringUtil.isNotBlank(query.getOrderStatus()))
			setOrderStatusSet(query);
		if(StringUtil.isNotBlank(query.getBusinessType()))
			setOrderbusinessTypeSet(query);
	}
	
	//订单查询状态的拆分
	private void setOrderStatusSet(QueryOrder query){
		String statusStr = query.getOrderStatus();
		Set<String> statsuSet = new HashSet<String>();
		if(StringUtil.isNotBlank(statusStr)){
			String[] statusS = statusStr.trim().split(",");
			for(int i=0,j=statusS.length; i<j; i++)
				if(StringUtil.isNotBlank(statusS[i]))
					statsuSet.add(statusS[i].trim());
			query.setOrderStatusSet(statsuSet);
		}
		query.setOrderStatus(null);
	}
	
	// 订单业务类型的拆分
	private void setOrderbusinessTypeSet(QueryOrder query){
		String typeStr = query.getBusinessType();
		Set<String> typeSet = new HashSet<String>();
		if(StringUtil.isNotBlank(typeStr)){
			String[] typeS = typeStr.trim().split(",");
			for(int i=0,j=typeS.length; i<j; i++)
				if(StringUtil.isNotBlank(typeS[i]))
					typeSet.add(typeS[i].trim());
			query.setBusinessTypeSet(typeSet);
		}
		query.setBusinessType(null);
	}
	/*====================== /一些小方法  ==========================*/

	@Override
	public QueryHbaseOrderResp findOrderFromHbase(QueryHbaseOrderRequest request, Integer pageSize) {
		QueryHbaseOrderResp resp = new QueryHbaseOrderResp();
		QueryOrder query = new QueryOrder();
		BeanUtils.copyProperties(request, query);
		HbaseQueryDO scanDumpOrder = dumpOrderHbaseDAO.scanDumpOrder(query, request.getNextPageStartRowKey(), pageSize);
		List<String> jsonDataList = scanDumpOrder.getJsonDataList();
		if(CollectionUtils.isEmpty(jsonDataList)) return resp;
		resp.setHasNextPage(scanDumpOrder.getHasNextPage());
		resp.setNextPageStartRowKey(scanDumpOrder.getNextPageStratRowKey());
		resp.setRows(jsonDataList);
		
		return resp;
	}

	@Override
	public List<String> findOrderExtend(String tradeOrderNo, int extendType) {
		List<String> data = dumpOrderHbaseDAO.findOrderExtend(tradeOrderNo, OrderExtendType.valueOf(extendType).getDesc());
		return data;
	}
	
	public static enum  OrderExtendType{	
		DETAIL(1,"q_detail"),
		PAY_FLOW(2,"q_pay_flow"),
		CALLBACK(3,"q_callback"),
		ACT_FLOW(4,"q_act_flow"),
		SETTLE_DETAIL(5,"q_settle_detail"),
		REFUND(6,"q_refund");
		int code;
		String desc;
		
		OrderExtendType(int code, String desc) {
			this.code = code;
			this.desc = desc;
		}
		
		public int getCode() {
			return code;
		}
		
		public void setCode(int code) {
			this.code = code;
		}
		
		public String getDesc() {
			return desc;
		}
		
		public void setDesc(String desc) {
			this.desc = desc;
		}	
		
		public static OrderExtendType valueOf(int code){			
			switch (code) {
			case 1:
				return DETAIL;
			case 2:
				return PAY_FLOW;
			case 3:
				return CALLBACK;
			case 4:
				return ACT_FLOW;
			case 5:
				return SETTLE_DETAIL;
			case 6:
				return REFUND;
			default:
				return null;
			}			
		}
	}

	@Override
	public PageModelResponse<UserAmountCollectResponse> queryAmountCollect(
			Date startDate, Date endDate,int pageNo,int pageSize) {
		ValidateUtil.notNull(startDate, "startDate不能为空！");
		ValidateUtil.notNull(endDate, "endDate不能为空！");
		ValidateUtil.gt(pageNo, 0, "pageNo不能小于1！");
		ValidateUtil.gt(pageSize, 0, "pageSize不能小于1！");
		
		String startDateStr = DateUtil.formatDate(startDate, DateUtil.SHORT_DATE_FORMAT_STR);
		String endDateStr = DateUtil.formatDate(endDate, DateUtil.SHORT_DATE_FORMAT_STR);
		
		PageModelResponse<UserAmountCollectResponse> repsonse = new PageModelResponse<UserAmountCollectResponse>();

		Integer count = userAmountCollectMysqlDAO.listCount(startDateStr, endDateStr);
		repsonse.setTotal(count);
		repsonse.setPageNo(pageNo);
		repsonse.setPageSize(pageSize);
		
		if(count >= 1){
			PageQuery pageQuery = new PageQuery(pageNo, pageSize);
			List<UserAmountCollectDO> listPage = userAmountCollectMysqlDAO.listPage(startDateStr, endDateStr, pageQuery );
			List<UserAmountCollectResponse> responseList = new ArrayList<UserAmountCollectResponse>();
			for (UserAmountCollectDO userAmountCollectDO : listPage) {
				UserAmountCollectResponse response = new UserAmountCollectResponse();
				response.setCashActCollectAmount(userAmountCollectDO.getCashActCollectAmount());
				response.setCashActFreezeCollectAmount(userAmountCollectDO.getCashActFreezeCollectAmount());
				response.setCashActNum(userAmountCollectDO.getCashActNum());
				response.setCollectDate(userAmountCollectDO.getCollectDate());
				response.setCollectTime(userAmountCollectDO.getCreateTime());
				response.setJfActCollectAmount(userAmountCollectDO.getJfActCollectAmount());
				response.setJfActFreezeCollectAmount(userAmountCollectDO.getJfActFreezeCollectAmount());
				response.setJfActNum(userAmountCollectDO.getJfActNum());
				response.setTradeActCollectAmount(userAmountCollectDO.getTradeActCollectAmount());
				response.setTradeActFreezeCollectAmount(userAmountCollectDO.getTradeActFreezeCollectAmount());
				response.setTradeActNum(userAmountCollectDO.getTradeActNum());
				response.setUserNum(userAmountCollectDO.getUserNum());
				responseList.add(response);
			}
			//responseList = ObjectUtil.copyProperties(listPage, responseList);
			repsonse.setList(responseList);
		}
		return repsonse;
	}

	@Override
	public QueryOrderStateResponse queryOrderState(String tradeOrderNo) {
		PayFlowDO flowDO = payFlowMysqlDAO.findByPayOrderId(tradeOrderNo);
		if (flowDO == null) {
			throw new BusinessException("该订单不存在!");
		}
		TradeRpcService tradeRpcService = dubboConsumerFactory.getDubboClient("gateWayTradeRpcService");
		ReqQryOrder request = new ReqQryOrder();
		request.setForceQry(true);
		request.setTradeOrderNo(flowDO.getGatewayOrderNo());
		RespQryOrder qryOrder = tradeRpcService.qryOrder(request);
		Integer tradeStatus = qryOrder.getTradeStatus();
		String tradeStatusDesc = qryOrder.getTradeStatusDesc();
		QueryOrderStateResponse resp = new QueryOrderStateResponse();
		if (tradeStatus == RespQryOrder.TS_ACCEPTED || tradeStatus == RespQryOrder.TS_PAYING) {
			resp.setPayStates(1);
			resp.setStateDesc("支付中");
		}
		if (tradeStatus == RespQryOrder.TS_SUCCEEDED) {
			resp.setPayStates(2);
			resp.setStateDesc("支付成功");
		}
		if (tradeStatus == RespQryOrder.TS_FAILED || tradeStatus == RespQryOrder.TS_UNKNOWN) {
			resp.setPayStates(3);
			resp.setStateDesc(tradeStatusDesc);
		}
		return resp;
	}

	
}
